package bean;

import java.util.HashMap;
import java.util.Map;

import org.ddpush.im.v1.client.appserver.Pusher;


public class DDPUSH implements Runnable{
	
	private final static String serverIp = "180.76.155.120";
	private final static int port = 9999;
	private  static byte[] uuid  = null;
	private byte[] data;
	
	private static Map<String, String> keyMap = new HashMap<String, String>(){
		{
			put("switch1", "S1");
			put("switch2", "S2");
			put("switch3", "S3");
			put("light", "L");
			put("window", "W");
			put("curtain", "C");
			put("door", "E");
			put("airCondition", "A");
		}
	};
	
	private static String Action(boolean action){
		return action?"O":"C";
	}
	
	public DDPUSH(byte[] data) {
		// TODO Auto-generated constructor stub
		this.data = data;
	}
	
	public DDPUSH(String senorName,boolean action){
		this((keyMap.get(senorName)+Action(action)).getBytes());
	}

	public void run() {
		// TODO Auto-generated method stub
		Pusher pusher = null;
		try{
			boolean result;
			DDPUSH.uuid = DDPUSHUtil.md5Byte("r134");
			pusher = new Pusher(serverIp, port, 1000*5);
			result = pusher.push0x20Message(uuid, data);
			if(result){
				Debug.print("DDPUSH", "OK");
			}else
				Debug.print("DDPUSH", "False");
		}catch(Exception e){
			return;
		}
	}

}